#!/usr/bin/env python
#-*- coding:utf-8 -*-

import tornado.web
from config.utils import get_settings
from controllers.base import BaseRequestHandler


class Login(BaseRequestHandler):
    def get(self):
        user = self.get_current_user()
        if user:
            self.redirect('/')
        context = {'xsrf_token': self.xsrf_token}
        template = self.template_env.get_template('users/login.html')
        self.write(template.render(**context))

    def post(self):
        user = self.get_current_user()
        if user:
            self.redirect('/')
        context = {}
        username = self.get_argument("username")
        password = self.get_argument("password")
        print("'%s'\t'%s'" % (username, password))
        context['username'] = username
        template = self.template_env.get_template('users/login.html')
        self.write(template.render(**context))


class Logout(BaseRequestHandler):
    def get(self):
        print(self._model_class)
        self.write("login")

    def post(self):
        self.write("login..")
